package com.zpc.rabbitmq.send;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zpc.rabbitmq.config.MqConfig;
/**
 * 生产信息
 * @author Dhjie
 *
 */
@Component
public class Sender {
	
	
	private static final Logger LOGGER=LoggerFactory.getLogger(Sender.class);
	@Autowired
	private RabbitTemplate rabbitTemplate;
	
	
	public void Sendtest() {
		
		for (int i = 0; i < 10; i++) {
			String mes="RabbitMQ_test"+i;
			LOGGER.info("发送：：：：："+mes);
			CorrelationData c=new CorrelationData(String.valueOf(i));
			rabbitTemplate.convertAndSend(MqConfig.EXCAHNGE_NAME,MqConfig.QUEUE_NAME, mes,c);
		}
	}
	
	
	
	public void Sendtest01() {
		for (int i = 0; i < 10000; i++) {
			String mes="RabbitMQ_test00"+i;
			LOGGER.info("发送：：：：："+mes);
			CorrelationData c=new CorrelationData(String.valueOf(i));
			rabbitTemplate.convertAndSend(MqConfig.EXCAHNGE_NAME, MqConfig.QUEUE_TEST_NAME, mes,c);
		}
	}
	
	
	/**
	 * 广播模式
	 */
	public void SendFanout() {
		for (int i = 0; i < 5; i++) {
			String mes="RabbitMQ_test00"+i;
			LOGGER.info("发送：：：：："+mes);
			CorrelationData c=new CorrelationData(String.valueOf(i));
			rabbitTemplate.convertAndSend(MqConfig.EXCAHNGE_FANOUT_NAME, "", mes,c);
		}
	}
	
	

}
